<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Backend_Form_User_Create
 *
 * @author Eugene
 */
class Backend_Form_User_Create extends Zend_Form
{

	/**
	 * @var array
	 */
	public $elementDecorators = array(
		'ViewHelper',
		'Errors',
		array(
			array('data' => 'HtmlTag'),
			array('tag' => 'td')
		),
		array(
			'Label',
			array('tag' => 'td')
		),
		array(
			array('row' => 'HtmlTag'),
			array('tag' => 'tr')
		)
	);

	/**
	 * @var array
	 */
	public $buttonDecorators = array(
		'ViewHelper',
		array(
			array('data' => 'HtmlTag'),
			array('tag' => 'td')
		),
		array(
			array('Label' => 'HtmlTag'),
			array('tag' => 'td', 'placement' => 'prepend')
		),
		array(
			array('row' => 'HtmlTag'),
			array('tag' => 'tr')
		)
	);

	/**
	 *
	 * @return void
	 */
	public function init()
	{
		$this->addElement('text', 'name', array(
			'label' => 'Name',
			'required' => true,
			'filters' => array('StringTrim'),
			'decorators' => $this->elementDecorators,
			'class' => 'grid_5 text ui-widget-content ui-corner-all',
			'validators' => array(
				array('Alnum'),
				array('StringLength', false, array(4, 255)),
			),
		));

		$this->addElement('select', 'role', array(
			'label' => 'Role',
			'required' => true,
			'decorators' => $this->elementDecorators,
			'class' => 'grid_5 text ui-widget-content ui-corner-all',
			'multiOptions' => array(
				Application_Model_User::ROLE_MEMBER => 'Member',
				Application_Model_User::ROLE_MANAGER => 'Manager'
			)
		));

		$this->addElement('text', 'email', array(
			'label' => 'Email',
			'required' => true,
			'decorators' => $this->elementDecorators,
			'class' => 'grid_5 text ui-widget-content ui-corner-all',
			'filters' => array('StringTrim'),
			'validators' => array(
				array('EmailAddress'),
				array('StringLength', false, array(6, 255)),
				array('Db_NoRecordExists', false, array(
						'table' => 'user',
						'field' => 'email'
				))
			),
		));

		$this->addElement('password', 'password', array(
			'label' => 'Password',
			'required' => true,
			'decorators' => $this->elementDecorators,
			'class' => 'grid_5 text ui-widget-content ui-corner-all',
			'validators' => array(
				array('StringLength', false, array(6, 255))
			),
		));

		$this->addElement('password', 'confirm', array(
			'label' => 'Confirm',
			'required' => true,
			'decorators' => $this->elementDecorators,
			'class' => 'grid_5 text ui-widget-content ui-corner-all',
			'validators' => array(
				array('StringLength', false, array(6, 255)),
				array('Identical', false, array('token' => 'password'))
			),
		));

		$this->addElement('checkbox', 'enabled', array(
			'label' => 'Enabled',
			'decorators' => $this->elementDecorators
		));

		$this->addElement('submit', 'create', array(
			'ignore' => true,
			'label' => 'Create',
			'decorators' => $this->buttonDecorators,
		));
	}

	/**
	 *
	 * @return void
	 */
	public function loadDefaultDecorators()
	{
		$this->setDecorators(array(
			'FormElements',
			array(
				'HtmlTag',
				array('tag' => 'table', 'class' => '')
			),
			'Form',
		));
	}

}